#include<bits/stdc++.h>
using namespace std;
namespace IO{
    const int BUF=1<<21;
    char buff[BUF],*p1=buff,*p2=buff;
    #define gc() (p1==p2&&(p2=((p1=buff)+fread(buff,1,BUF,stdin)),p1==p2)?EOF:*p1++)
    template<typename T>inline void read(T &x){
        char ch=gc();x=0;int f=1;
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
        while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=gc();
        x*=f;
    }
    char obuf[BUF],*p3=obuf;
    inline void pc(char ch){
        if(p3-obuf<BUF) *p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    inline void put(const char *s){while(*s) pc(*s),++s;}
    char ch[32],ctop;
    template<typename T>inline void print(T x){
    	if(x<0) x=~x+1,pc('-');
        if(!x) return pc(48);
        while(x) ch[++ctop]=x%10^48,x/=10;
        while(ctop) pc(ch[ctop--]);
    }
    inline void flush(){fwrite(obuf,p3-obuf,1,stdout);p3=obuf;}
}
using namespace IO;
const int N=4e5+5,mod=998244353; 
#define i128 __int128
int n,v[N],c[N],x[N],cnt,len;
struct node{
	long long l,r;
	i128 k,b;
}f[N],tmp[N];
inline void push(int i,node now){
	
	if(-now.k<v[i]) now.b+=(v[i]+now.k)*(now.r-now.l),now.k=-v[i];
	i128 rv=now.b+(now.r-now.l)*now.k;
	if(len&&tmp[len].b+v[i]>rv) now.b+=tmp[len].b+v[i]-rv;
	tmp[++len]=now;
}
int main(){
	freopen("b.in","r",stdin);
	freopen("b.out","w",stdout);
	read(n);
	for(int i=1;i<=n;++i) read(v[i]);
	for(int i=1;i<=n;++i) read(c[i]);
	bool sub1=1,sub2=1;
	for(int i=1;i<n;++i) read(x[i]),sub1&=(x[i]==1),sub2&=(x[i]==1000000000);
	if(sub1){
		int mx=0;
		i128 ans=0;
		for(int i=n;i;--i){
			mx=max(mx,v[i]);
			ans+=1ll*mx*c[i];
		}
		return cout<<(int)(ans%mod),0;
	}
	if(sub2){
		i128 ans=0;
		for(int i=1;i<=n;++i){
			i128 val=1ll*c[i]*v[i];
			if(c[i]==1000000000&&i<n) val=max(val,(i128)v[i+1]);
			ans+=val;
		}
		return cout<<(int)(ans%mod),0;
	}
	f[cnt=1]={0,0,0,0};
	x[0]=1;
	for(int i=1;i<=n;++i){
		len=0;
		for(int j=1;j<=cnt;++j){
			long long l=(f[j].l+x[i-1]-1)/x[i-1]+c[i],r=f[j].r/x[i-1]+c[i];
			if(l<=r)
				push(i,(node){l,r,f[j].k*x[i-1],f[j].b+f[j].k*((l-c[i])*x[i-1]-f[j].l)});
		}
		if(c[i]) push(i,(node){0,c[i]-1,-v[i],1ll*c[i]*v[i]});
		cnt=len;
		for(int j=1;j<=cnt;++j) f[j]=tmp[j];
	}
	printf("%lld",(long long)(f[cnt].b%mod));
	return 0;
}


